mui.plusReady(function() {
	var btn_img = document.getElementById("btn_img");
	var screenWidth = document.documentElement.clientWidth;
	var screenHeight = document.documentElement.clientHeight;
	var m_top;
	//图片上传
	btn_img.addEventListener("tap", function() {
		Galleryimg();
	});

	function Galleryimg() {
		plus.gallery.pick(function(path) {
			var imgsrc = document.createElement("img");
			showimg(path, imgsrc);
		}, function(e) {
			plus.nativeUI.toast("取消图片选择");
		}, {
			filter: "image"
		});
	}
	//处理图片
	function showimg(url, img_src) {
		// 兼容以“file:”开头的情况
		if(0 != url.toString().indexOf("file://")) {
			url = "file://" + url;
		}
		var _img_ = new Image();
		_img_.src = url;
		_img_.onclick = function() {
			plus.runtime.openFile(url);
		};
		_img_.onload = function() {
			var tmph = _img_.height;
			var tmpw = _img_.width;
			var isHengTu = tmpw > tmph;
			var max = Math.max(tmpw, tmph);
			var min = Math.min(tmpw, tmph);
			var bili = min / max;
			if(max > 1200) {
				max = 1200;
				min = Math.floor(bili * max);
			}
			tmph = isHengTu ? min : max;
			tmpw = isHengTu ? max : min;
			plus.io.resolveLocalFileSystemURL(url, function(entry) {
					entry.file(function(file) {
						canvasResize(file, {
							width: tmpw,
							height: tmph,
							crop: false,
							quality: 30, //压缩质量
							rotate: 0,
							callback: function(data, width, height) {
								var filesize = (file.size / 1024) / 1024;
								if(mui.os.ios && filesize > 10) {
									plus.nativeUI.toast("请选择不超过10M的图片上传");
									return;
								}
								/*
								 * 1. 以下代码放到你们显示图片的位置即可
								 */
								//scale为屏幕宽度/图片宽度的比例。然后确定图片高度equalHeight
								var btn_images = document.getElementById("btn_images");
								var scale = (screenWidth) / tmpw;
								equalHeight = tmph * scale;
								if(equalHeight > equalHeight*0.3){
									img_src.width = screenWidth;
									m_top = (equalHeight - equalHeight*0.3)/2;
								}
								img_src.name = data;
								img_src.src = url;
								plus.nativeUI.closeWaiting();
							}
						}); 
					});
				},
				function(e) {
					plus.nativeUI.closeWaiting();
				});
			checkImages(img_src);
		};
	}
	//图片显示
	function checkImages(img_src) {
		var titleInfo = document.getElementById("titleInfo");
		imgList.insertBefore(img_src, titleInfo);
		img_src.onload = function() {
			this.parentNode.style.height = this.parentNode.offsetWidth + "px";
			if(this.width < this.height) {
				this.style.width = "100%";
				this.style.marginTop = "-" + m_top + "px";
			}
		}
	}
	/*
	 * 2. 以下全部内容复制到你们js中
	 */
	var imgList = document.getElementById("imgList");
	var img_shows = document.getElementById("img_shows");
	var slider = document.getElementById("slider");
	//显示大图，浮层图
	imgList.addEventListener("tap", function() {
		jQuery("#bigImg").attr("src", jQuery("#imgList img")[0].src);
		img_show();
	})

	//查看大图的图片加载方法 
	img_load2 = function(img) {
		img.style.width = screenWidth * 0.8 + "px";
		img.style.marginLeft = screenWidth * 0.1 + "px";
		img.style.marginTop = (screenHeight - img.height) * 0.5 + "px";
	}

	//点击查看大图的方法  
	img_show = function() {
		img_shows.style.display = "block";
		slider.style.display = "block";
		//		var gallery = mui('.mui-slider').slider();
		//		gallery.gotoItem();
	}
	//隐藏浮层图
	img_shows.addEventListener("tap", function() {
		img_shows.style.display = "none";
		slider.style.display = "none";
	})
	//隐藏浮层图
	slider.addEventListener("tap", function() {
		img_shows.style.display = "none";
		slider.style.display = "none";
	})

})